package com.mcr.reggie.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
public class MailUtils {
    @Value("${sendMail.prefix}")
    private String prefix;
    @Value("${sendMail.suffix}")
    private String suffix;
    @Value("${sendMail.subject}")
    private String subject;
    @Value("${spring.mail.username}")
    private String from;//获取发件邮箱
    @Autowired
    private JavaMailSender mailSender;
    public void sendByQQEmail(String sendMail,String code){
        String msg=prefix+code+suffix;
        SimpleMailMessage message=new SimpleMailMessage();
        message.setFrom(from);//设置发件人
        message.setTo(sendMail);//设置收件人
        message.setSubject(subject);//设置邮箱主题
        message.setText(msg);//设置邮件内容
        mailSender.send(message);//发件
    }
}
